package com.xw.musicplayer.listener;

import android.content.Context;

import java.io.IOException;

public interface IMediaPlayer {

    int MEDIA_INFO_BUFFERING_START = 701;
    int MEDIA_INFO_BUFFERING_END = 702;

    /**
     * 初始化播放内核
     *
     * @param context 上下文
     */
    void init(Context context);

    /**
     * 异步准备资源.
     */
    void prepareAsync() throws IllegalArgumentException;

    /**
     * 释放内核
     */
    void release();

    /**
     * 开始播放.
     */
    void start() throws IllegalStateException;

    /**
     * 停止播放.
     */
    void stop() throws IllegalStateException;

    /**
     * 暂停播放.
     */
    void pause() throws IllegalStateException;

    /**
     * 复位.
     */
    void reset();

    /**
     * 设置播放源.
     *
     * @param path path
     */
    void setDataSource(String path) throws IOException, IllegalArgumentException, SecurityException, IllegalStateException;

    /**
     * 获取当前播放状态.
     *
     * @return true当前正在播放, 反之false
     */
    boolean isPlaying();

    /**
     * 跳转到某个时间节点.
     *
     * @param milliseconds 时间节点
     */
    void seekTo(long milliseconds) throws IllegalStateException;

    /**
     * 获取当前播放进度.
     *
     * @return 播放进度
     */
    long getCurrentPosition();

    /**
     * 获取整个播放时长.
     *
     * @return 总时长
     */
    long getDuration();

    String getDataSource();

    /**
     * 设置监听
     */
    void setOnPreparedListener(OnPreparedListener listener);

    /**
     * 设置监听
     */
    void setOnCompletionListener(OnCompletionListener listener);

    /**
     * 设置监听
     */
    void setOnBufferingUpdateListener(OnBufferingUpdateListener listener);

    /**
     * 设置监听
     */
    void setOnSeekCompleteListener(OnSeekCompleteListener listener);

    /**
     * 设置监听
     */
    void setOnErrorListener(OnErrorListener listener);

    /**
     * 设置监听
     */
    void setOnInfoListener(OnInfoListener listener);

    interface OnPreparedListener {
        void onPrepared(IMediaPlayer mp);
    }

    interface OnCompletionListener {
        void onCompletion(IMediaPlayer mp);
    }

    interface OnBufferingUpdateListener {
        void onBufferingUpdate(IMediaPlayer mp, int percent);
    }

    interface OnSeekCompleteListener {
        void onSeekComplete(IMediaPlayer mp);
    }

    interface OnErrorListener {
        boolean onError(IMediaPlayer mp, int what, int extra);
    }

    interface OnInfoListener {
        boolean onInfo(IMediaPlayer mp, int what, int extra);
    }
}
